﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.IdentityModel.Tokens;
using System.ServiceModel.Channels;
using System.Xml;
using System.Xml.Linq;
using System.ServiceModel.Security;

namespace SecurityTokenServiceNS
{
    public sealed class RSTR : BodyWriter
    {
		private int _keySize;
		private SecurityToken _requestedSecurityToken;
		private SecurityToken _requestedProofToken;
		private SecurityToken _entropy;
		private SecurityKeyIdentifierClause _requestedAttachedReference;
		private SecurityKeyIdentifierClause _requestedUnattachedReference;
		private string _lifetime;

		private RST _rst;

		private string _wst;
        private bool _computedKey;

        public RSTR(RST rst)
            : base(true)
        {
			_rst = rst;
			_wst = rst.NamespaceUri.ToString();
        }

        #region Properties

		public RST RST
		{
			get { return _rst; }
		}
        public int KeySize
        {
            get { return _keySize; }
            set { _keySize = value; }
        }
        public SecurityToken RequestedSecurityToken
        {
            get { return _requestedSecurityToken; }
            set { _requestedSecurityToken = value; }
        }
        public SecurityToken RequestedProofToken
        {
            get { return _requestedProofToken; }
            set { _requestedProofToken = value; }
        }
        public SecurityToken Entropy
        {
            get { return _entropy; }
            set { _entropy = value; }
        }
        public SecurityKeyIdentifierClause RequestedAttachedReference
        {
            get { return _requestedAttachedReference; }
            set { _requestedAttachedReference = value; }
        }
        public SecurityKeyIdentifierClause RequestedUnattachedReference
        {
            get { return _requestedUnattachedReference; }
            set { _requestedUnattachedReference = value; }
        }
		public string Lifetime
		{
		    get { return _lifetime; }
		    set { _lifetime = value; }
		}
        public bool ComputedKey
        {
            get { return _computedKey; }
            set { _computedKey = value; }
        }

        #endregion

        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
			XDocument xRstr = new XDocument();

			foreach (IRSTRProcessor rstrp in AddInTool.RstrProcessorModules)
			    rstrp.ProcessRstr(this, ref xRstr);

			xRstr.Root.WriteTo(writer);
		}
    }
}
